package nuc.ss.novel.entity;

import java.util.Date;

/**
 * @author : zzr
 * @description :这是用户实体类 导入了Serializable和Date包
 *               Serializable表明该类的对象可以被序列化（存储到文件中）
 *                Data包用于处理与时间相关的属性
 * @date :2024_12_18
 */
public class User {

    // 下面是用户基本信息

    //用户id
    private Integer id;
    //用户名
    private String username;
    //密码
    private String password;
    //姓名
    private String nickname;
    //性别：用0表示男，1表示女
    private Integer sex;
    //生日
    private String brithday;
    //电话
    private String telephone;
    //邮箱
    private String email;
    //职业
    private String profession;

    //添加了两个Date类型的变量

    //添加时间
    private Date createTime;
    //修改时间
    private Date updateTime;

    //get and set 方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getBrithday() {
        return brithday;
    }

    public void setBrithday(String brithday) {
        this.brithday = brithday;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    //重写toString方法 此处只需要返回姓名即可
    @Override
    public String toString() {
        return nickname;
    }

    /*
    重写Object中的equals方法，比较两个对象是否相等
    用途：在集合类List，Set中判断User对象是否已经存在在，避免重复
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {  // 先判断传入的obj对象是否为null
            return false;
        }
        //obj不为null之后，用User声明一个user对象来接收obj，但obj类型的Object，需要(User)强制类型转换
        User user = (User)obj;
        //然后比较id和nickname属性，则认为两个对象相等
        if (this.id == user.getId() &&this.nickname.equals(user.getNickname())) {
            return true;
        }
        return false;
    }
}
